package com.xin.di.uav.applet.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.xin.di.uav.applet.mapper.PermissionMapper;
import com.xin.di.uav.applet.service.PermissionService;
import com.xin.di.uav.common.response.TreeResp;
import com.xin.di.uav.common.utils.BeanUtil;
import com.xin.di.uav.common.utils.TreeNodeTree;
import com.xin.di.uav.operate.po.PermissionPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public List<TreeResp> list() {
        List<PermissionPO> permissions = permissionMapper.selectList();
        if (CollectionUtil.isNotEmpty(permissions)) {
            List<TreeResp> treeRespList = new ArrayList<>();
            for (PermissionPO permission : permissions) {
                TreeResp treeResp = BeanUtil.copyProperties(permission, TreeResp.class);
                treeResp.setLabel(permission.getPermName());
                treeRespList.add(treeResp);
            }
            return TreeNodeTree.buildTree(treeRespList);

        }

        return new ArrayList<>();
    }

}
